package com.Arr;

import java.util.Scanner;

/*
数组的定义和使用
*/
public class Demo01 {
    public static void main(String[] args) {
        int[] arr = new int[]{1, 2, 3, 4, 5, 6};
        //改变第三位为7
        arr[2] = 7;
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
        }
        System.out.println();
        //获取数组的长度
        System.out.println("数组的长度为：" + arr.length);

        //获取越界数组
//        System.out.println(arr[6]);


        //定义动态数组
        int[] b = new int[6];
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        for (int i = 0; i < b.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个数组：");
            int date = sc.nextInt();
            arr[i] = date;

        }
        for (int i = 0; i < b.length; i++) {
            System.out.print(arr[i] + "\t");
            sum += arr[i];
        }
        System.out.println();
        System.out.print("数组的和为：" + sum);
    }
}
